import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

extension StringExt on String {
  Future<void> showSuccess() {
    return SmartDialog.showToast(
      this,
      alignment: Alignment.center,
      displayType: SmartToastType.onlyRefresh,
      builder: (context) {
        return Container(
          constraints: const BoxConstraints(minWidth: 100),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10),
            color: Colors.black.withOpacity(0.7),
          ),
          padding: const EdgeInsets.only(top: 12, left: 12.5, right: 12.5, bottom: 12),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const Icon(Icons.done, color: Colors.white, size: 30),
              Container(
                margin: const EdgeInsets.only(top: 10),
                child: Text(
                  this,
                  style: const TextStyle(fontSize: 16.5, color: Colors.white),
                  textAlign: TextAlign.center,
                ),
              ),
            ],
          ),
        );
      },
    );
  }

  Future<void> showInfo() {
    return SmartDialog.showToast(
      this,
      alignment: Alignment.center,
      displayType: SmartToastType.last,
      builder: (context) {
        return Container(
          constraints: const BoxConstraints(minWidth: 100),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10),
            color: Colors.black.withOpacity(0.7),
          ),
          padding: const EdgeInsets.only(top: 12, left: 12.5, right: 12.5, bottom: 12),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const Icon(Icons.info_outline, color: Colors.white, size: 30),
              Container(
                margin: const EdgeInsets.only(top: 10),
                child: Text(
                  this,
                  style: const TextStyle(fontSize: 16.5, color: Colors.white),
                  textAlign: TextAlign.center,
                ),
              ),
            ],
          ),
        );
      },
    );
  }

  Future<void> showError() {
    return SmartDialog.showToast(
      this,
      alignment: Alignment.center,
      displayType: SmartToastType.onlyRefresh,
      builder: (context) {
        return Container(
          constraints: const BoxConstraints(minWidth: 100),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10),
            color: Colors.black.withOpacity(0.7),
          ),
          padding: const EdgeInsets.only(top: 12, left: 12.5, right: 12.5, bottom: 12),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const Icon(Icons.clear, color: Colors.white, size: 30),
              Container(
                margin: const EdgeInsets.only(top: 10),
                child: Text(
                  this,
                  style: const TextStyle(fontSize: 16.5, color: Colors.white),
                  textAlign: TextAlign.center,
                ),
              ),
            ],
          ),
        );
      },
    );
  }

  void push({Map<String, dynamic>? arguments}) {
    BoostNavigator.instance.push(this, arguments: arguments);
  }

  void popUntil() {
    BoostNavigator.instance.popUntil(route: this);
  }
}

extension NullableStringExt on String? {
  bool get isNullOrEmpty => this == null || this?.isEmpty == true;
}
